package com.bestcem.xm.common.core.sql.calculator;

import com.bestcem.xm.common.core.sql.ConditionConstant;
import com.bestcem.xm.common.core.sql.ConditionProxy;
import com.bestcem.xm.common.core.sql.ParamsProxy;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

/**
 * @author dc.wang <dc.wang@idiaoyan.com>
 * @version V1.0
 * @description not in condition calculator
 * @date 2021/5/26
 */
@Slf4j
public class NinConditionCalculator extends ConditionCalculator{
    public NinConditionCalculator(ConditionProxy conditionProxy, ParamsProxy paramsProxy) {
        super(conditionProxy, paramsProxy);
    }

    @Override
    protected List<String> getSupportedDataTypes() {
        return Arrays.asList(ConditionConstant.FieldTypes.STRING);
    }

    @Override
    protected String getOperator() {
        return ConditionConstant.Operators.NIN;
    }

    /**
     * 默认返回值
     */
    @Override
    protected boolean getDefaultResult() {
        return true;
    }

    @Override
    protected boolean onCalculate() {
        List<Object> conditionValues = this.conditionProxy.listValues();
        Object paramValue = this.getParamValue();

        // 参数校验
        if(paramValue == null){
            return this.getDefaultResult();
        }

        return conditionValues.stream().noneMatch(paramValue::equals);
    }
}